package com.quanquan.management.controller;

import DTO.PageDTO;
import com.quanquan.management.dto.SystemLogDTO;
import com.quanquan.management.request.SystemLogRequestBody;
import com.quanquan.management.service.SystemLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * 功能描述:
 *
 * @ClassName: SystemLogController
 * @Author: xiaoqianh丶
 * @Date: 2019-08-22 16:32
 * @Version: V1.0
 */
@Controller
@RequestMapping("/system_log")
public class SystemLogController extends ManagerBaseController {

    @Value("${module-url.storeUrl}")
    private String storeUrl;

    @Autowired
    private SystemLogService systemLogService;

    /**
     * 日志列表
     *
     * @param
     * @param model
     * @return
     */
    @GetMapping("/list")
    public String list(@RequestParam(required = false) Integer pageSize,
                       @RequestParam(required = false) Integer page,
                       @RequestParam(required = false) String keyword,
                       @RequestParam(required = false) String fromDate,
                       @RequestParam(required = false) String toDate,
                       @RequestParam(required = false) String sort,
                       @RequestParam(required = false) boolean isAsc, Model model ) {
        if (null == pageSize) {
            pageSize = 10;
        }
        if (null == page) {
            page = 0;
        } else if (page > 0){
            page = page -1;
        }
        SystemLogRequestBody systemLogRequestBody = new SystemLogRequestBody();
        systemLogRequestBody.setPage(page);
        systemLogRequestBody.setSize(pageSize);
        systemLogRequestBody.setKeyword(keyword);
        systemLogRequestBody.setFromDate(fromDate);
        systemLogRequestBody.setToDate(toDate);
        PageDTO<SystemLogDTO> allLogs = systemLogService.findAllLogs(systemLogRequestBody);
        model.addAttribute("pageObj", allLogs);
        return "systemLog/list";
    }


}
